﻿using System.Collections.Generic;
using DCT.Model;

namespace DCT.ViewModel
{
    public class DeviceViewModelFactory
    {
        public static List<DeviceBaseViewModel> GenerateDeviceViewModel(DeviceBaseModel deviceModel, DeviceBaseGraphModel deviceGraphModel)
        {
            List<DeviceBaseViewModel> deviceBaseViewModels = new List<DeviceBaseViewModel>();

            // 或者可以用DeviceBaseModel的DeviceType属性来判断
            switch (deviceModel.GetType().Name)
            {
                case "TrackSegmentModel":
                    TrackSegmentViewModel sts = new TrackSegmentViewModel((TrackSegmentModel)deviceModel, (TrackSegmentGraphModel)deviceGraphModel, TrackSegmentViewModelType.Start);
                    TrackSegmentViewModel ets = new TrackSegmentViewModel((TrackSegmentModel)deviceModel, (TrackSegmentGraphModel)deviceGraphModel, TrackSegmentViewModelType.End);

                    sts.SetAnotherTrackSegmentViewModel(ets);
                    ets.SetAnotherTrackSegmentViewModel(sts);

                    deviceBaseViewModels.Add(sts);
                    deviceBaseViewModels.Add(ets);
                    break;
                case "SwitchModel":
                    SwitchViewModel mswvm = new SwitchViewModel((SwitchModel)deviceModel, (SwitchGraphModel)deviceGraphModel, SwitchViewModelType.Merge);
                    SwitchViewModel nswvm = new SwitchViewModel((SwitchModel)deviceModel, (SwitchGraphModel)deviceGraphModel, SwitchViewModelType.Normal);
                    SwitchViewModel rswvm = new SwitchViewModel((SwitchModel)deviceModel, (SwitchGraphModel)deviceGraphModel, SwitchViewModelType.Reverse);

                    mswvm.SetOtherSwitchViewModel(nswvm);
                    mswvm.SetOtherSwitchViewModel(rswvm);

                    nswvm.SetOtherSwitchViewModel(mswvm);
                    nswvm.SetOtherSwitchViewModel(rswvm);

                    rswvm.SetOtherSwitchViewModel(mswvm);
                    rswvm.SetOtherSwitchViewModel(nswvm);

                    deviceBaseViewModels.Add(mswvm);
                    deviceBaseViewModels.Add(nswvm);
                    deviceBaseViewModels.Add(rswvm);
                    break;
                case "SignalModel":
                    SignalViewModel sgvm = new SignalViewModel((SignalModel)deviceModel, (SignalGraphModel)deviceGraphModel);
                    deviceBaseViewModels.Add(sgvm);
                    break;
                case "AxleModel":
                    AxleViewModel axvm = new AxleViewModel((AxleModel)deviceModel, (AxleGraphModel)deviceGraphModel);
                    deviceBaseViewModels.Add(axvm);
                    break;
                case "PlatformModel":
                    PlatformViewModel pfvm = new PlatformViewModel((PlatformModel)deviceModel, (PlatformGraphModel)deviceGraphModel);
                    deviceBaseViewModels.Add(pfvm);
                    break;
                case "MiscellaneousDeviceModel":
                    MiscellaneousDeviceViewModel mdvm = new MiscellaneousDeviceViewModel((MiscellaneousDeviceModel)deviceModel, (MiscellaneousDeviceGraphModel)deviceGraphModel);
                    deviceBaseViewModels.Add(mdvm);
                    break;
                default:
                    break;
            }

            return deviceBaseViewModels;
        }
    }
}
